﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ZYL
{
    class Program
    {
        static void Main(string[] args)
        {
            Wanjia w = new Wanjia();
            Jiqi j = new Jiqi();
            Caipan c = new Caipan();
            int aa = 0;
            int bb = 0;
            int cc = 0;
            string flag = null;
        logio:
            Front();

            Console.WriteLine("出拳规则：{0}", ListFist());
            Console.WriteLine("请选择对方角色<{0}>", Machinename());
            int key = int.Parse(Console.ReadLine());
            j.Name = ((Man)key).ToString();
            Console.WriteLine("请输入您的姓名：");
            w.Name = Console.ReadLine();
            
            while (true)
            {
                Console.WriteLine("{0}vs{1}\t对战", w.Name, j.Name);
                Console.WriteLine("开始游戏吗？（y/n）");
                flag = Console.ReadLine();
                if (flag.Equals("y"))
                {
                    break;
                }
            }
            while (true)
            {
                Console.WriteLine("\n\r请出拳：{0}(输入相应数字：)", ListFist());
                int gnum = w.ShowFist();
                int mannum = j.ShowFist();
                Console.WriteLine("{0}：出拳：{1}", w.Name, (Fist)gnum);
                Console.WriteLine("{0}：出拳：{1}", j.Name, (Fist)mannum)
                int a = c.Port(gnum, mannum);
                User(a, w.Name);
                if (a == 1)
                {
                    cc++;
                }
                if (a == -1)
                {
                    bb++;
                }
                aa++;
                Console.WriteLine("是否开始进行下一轮？（y/n）");
                flag = Console.ReadLine();
                if (flag.Equals("n"))
                {
                    break;
                }
            }
            Console.WriteLine("===========================");
            Console.WriteLine("{0}\tvs\t{1}", j.Name, w.Name);
            Console.WriteLine("对战次数：{0}", aa);
            Console.WriteLine("姓名\t得分");
            Console.WriteLine("{0}\t{1}", w.Name, cc);
            Console.WriteLine("{0}\t{1}", j.Name, bb);
            if (cc > bb)
            {
                Console.WriteLine("胜利");
            }
            else
            {
                Console.WriteLine("失败");
            }
            Console.WriteLine("要开始进行下一轮？（y/n）");
            flag = Console.ReadLine();
            if (flag.Equals("y"))
            {
                aa = 0;
                bb = 0;
                cc = 0;
                goto logio;
            }
            else
            {
                Console.WriteLine("退出");
            }
        }

        private static void Front()
        {
            Console.WriteLine("-------------欢迎进入游戏世界---------------");
            Console.WriteLine("***************************");
            Console.WriteLine("*********猜拳，开始********");
            Console.WriteLine("***************************");
        }

        private static void User(int a, string name)
        {
            if (a == 0)
            {
                Console.WriteLine("平局");
            }
            else if (a == 1)
            {
                Console.WriteLine("赢了", name);
            }
            else
            {
                Console.WriteLine("败了");
            }
        }
        
        static string ListFist()
        {
            string fistString = "";
            int i = 1;
            foreach (Fist f in Enum.GetValues(typeof(Fist)))
            {
                fistString += i + "、" + f + "；";
                i++;
            }
            return fistString;
        }
        
        static string Machinename()
        {
            string fistString = "";
            int i = 1;
            foreach (Man m in Enum.GetValues(typeof(Man)))
            {
                fistString += i + "：" + m + "；";
                i++;
            }
            return fistString;
        }
    }
}
